package com.tianxinweb.entity;

import com.baomidou.mybatisplus.enums.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;

/**
 * <p>
 * 
 * </p>
 *
 * @author cboy
 * @since 2018-07-19
 */
@TableName("tx_admin")
public class Admin implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "admin_id", type = IdType.AUTO)
    private Integer adminId;
    /**
     * 管理员名称
     */
    @NotNull
    @Pattern(regexp="^[a-zA-Z0-9_@]{4,16}$",message="用户名必须是4-16位数字，字母或下划线_或@")
    private String adminName;
    /**
     * 管理员密码
     */
    @NotNull
    @Length(min = 32,max = 32,message = "长度不正确")
    private String adminPwd;
    /**
     * md5加密盐值
     */
    private String pwdSalt;
    /**
     * 管理员最后登录ip
     */
    private String lastLoginIp;
    /**
     * 管理员最后登录时间
     */
    private Date lastLoginTime;
    /**
     * 管理员登录总次数
     */
    private Integer loginCount;
    /**
     * 权限id列表，json数据
     */
    private String privIds;
    /**
     * 管理员角色id列表，json数据
     */
    private String roleIds;
    /**
     * 管理员状态，默认为0，表示正常，1表示已被禁用
     */
    private Boolean adminStatus;
    /**
     * 管理员创建时间
     */
    private Date createTime;

    @Length(min = 32,max = 32,message = "长度不正确")
    private transient String comfirmPwd;


    public Integer getAdminId() {
        return adminId;
    }

    public void setAdminId(Integer adminId) {
        this.adminId = adminId;
    }

    public String getAdminName() {
        return adminName;
    }

    public void setAdminName(String adminName) {
        this.adminName = adminName;
    }

    public String getAdminPwd() {
        return adminPwd;
    }

    public void setAdminPwd(String adminPwd) {
        this.adminPwd = adminPwd;
    }

    public String getPwdSalt() {
        return pwdSalt;
    }

    public void setPwdSalt(String pwdSalt) {
        this.pwdSalt = pwdSalt;
    }

    public String getLastLoginIp() {
        return lastLoginIp;
    }

    public void setLastLoginIp(String lastLoginIp) {
        this.lastLoginIp = lastLoginIp;
    }

    public Date getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(Date lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public Integer getLoginCount() {
        return loginCount;
    }

    public void setLoginCount(Integer loginCount) {
        this.loginCount = loginCount;
    }

    public String getPrivIds() {
        return privIds;
    }

    public void setPrivIds(String privIds) {
        this.privIds = privIds;
    }

    public String getRoleIds() {
        return roleIds;
    }

    public void setRoleIds(String roleIds) {
        this.roleIds = roleIds;
    }

    public Boolean getAdminStatus() {
        return adminStatus;
    }

    public void setAdminStatus(Boolean adminStatus) {
        this.adminStatus = adminStatus;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getComfirmPwd() {
        return comfirmPwd;
    }

    public void setComfirmPwd(String comfirmPwd) {
        this.comfirmPwd = comfirmPwd;
    }

    @Override
    public String toString() {
        return "Admin{" +
        ", adminId=" + adminId +
        ", adminName=" + adminName +
        ", adminPwd=" + adminPwd +
        ", pwdSalt=" + pwdSalt +
        ", lastLoginIp=" + lastLoginIp +
        ", lastLoginTime=" + lastLoginTime +
        ", loginCount=" + loginCount +
        ", privIds=" + privIds +
        ", roleIds=" + roleIds +
        ", adminStatus=" + adminStatus +
        ", createTime=" + createTime +
        "}";
    }

    public boolean validatePwd() {
        if(this.comfirmPwd == null){
            return false;
        }
        if(!this.adminPwd.equals(this.comfirmPwd)){
            return false;
        }
        return true;
    }
}
